package com.hy.study.practice.sparse;

import java.io.*;
import java.util.Arrays;

/**
 * 使用稀疏数组压缩文件
 */
public class SparseArrayZipFile {
    private final static String filePath="F:\\Downloads\\node-v14.17.0-x64.msi";
    public static void main(String[] args) {
        //读取文件成为01的二进制
        byte[] fileByte = readFile(filePath);
        System.out.println(Arrays.toString(fileByte));

    }

    private static byte[] readFile(String filePath) {
        try {
            File file = new File(filePath);
            FileInputStream fileInputStream = new FileInputStream(file);
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int len = 0;
            while ((len = fileInputStream.read(buffer)) != -1) {
                byteArrayOutputStream.write(buffer, 0, len);
            }
            fileInputStream.close();
            byteArrayOutputStream.close();
            return byteArrayOutputStream.toByteArray();
        } catch (FileNotFoundException e) {
            System.err.println("文件没有找到");
        } catch (IOException e) {
            System.out.println("获取文件异常");
        }
        return null;
    }
}
